import Vue from 'vue'
import Router from 'vue-router'
// @ts-ignore
import middle from '../components/middle.vue'
// @ts-ignore
import maincontent from '../components/maincontent.vue'
// @ts-ignore
import publishArticle from '../components/PublishArticle.vue'
// @ts-ignore
import recored from '../components/record.vue'
// @ts-ignore
import showblogcontent from '../components/Showblogcontent.vue'
// @ts-ignore
import love from '../components/love'
import store from '../store/index'
Vue.use(Router)
    // @ts-ignore
import Postablog from '../components/Postablog'
const router = new Router({
    routes: [{
        path: '/',
        component: middle,
        children: [{
                path: '/',
                component: maincontent,
            },
            {
                name: 'publishArticle',
                path: 'publishArticle',
                component: publishArticle,
                children: [{
                    name: 'publishArticlecontent',
                    path: 'publishArticlecontent',
                    component: showblogcontent,
                }]
            },
            {
                path: 'recored',
                component: recored,
            },
            {
                path: 'Postablog',
                component: Postablog,
                meta: { isAuth: true },
            }
        ]

    }, {
        name: 'love',
        path: '/love',
        component: love,
    }]


})

router.beforeEach((to, from, next) => {
    // console.log(to, from, next)
    if (to.meta.isAuth) {
        if (store.state.token) {
            next()
        } else {
            next({
                path: '/',
            })
        }
    } else {
        next()
    }


})


export default router